
import java.io.IOException;

/**
 * Starts up a multi threaded proxy or event proxy server based on command line input
 * @author hussein
 */
public class main {

    public static void main(String[] args) {
        int port = 8080;
        String serverType = "MT";
        boolean hasCache = true;

        //Read command line arguments
        if (args.length < 1) {
            System.out.println("Startup arguments: Port, ServerType(MT for multithreaded or E for event based");
            System.out.println("Example: java proxyserver 8080 MT");
            System.out.println("Example: java proxyserver 8080 E");
            System.exit(0);
        } else if (args.length == 1) {
            port = Integer.parseInt(args[0]);
        } else if (args.length == 2) {
            port = Integer.parseInt(args[0]);
            serverType = args[1];
        } else {
            port = Integer.parseInt(args[0]);
            serverType = args[1];
            hasCache = false;
        }

        //Run Multi-threaded server
        if (!serverType.equalsIgnoreCase("MT")) {
            try {
                Server server = new Server(port, hasCache);
                server.startServer();
            } catch (IOException ex) {
                System.out.println(ex.getMessage());
            }
        }
        //Run Event-based server
        else {
            try {
                EventServer server = new EventServer(port, hasCache);
                server.startServer();
            } catch (IOException ex)  {
                System.out.println(ex.getMessage());
            }
        }
    }
}
